<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-card class="search-card">
      <el-form
        :model="queryParams"
        ref="queryParams"
        size="small"
        label-width="88px"
        class="formBox"
      >
        <el-row :gutter="0">
          <el-col :span="5">
            <el-form-item label="姓名" prop="name">
              <el-input
                v-model="queryParams.name"
                placeholder="请输入姓名"
                clearable
                maxlength="50"
                show-word-limit
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="身份证号" prop="idCardNumber">
              <el-input
                v-model="queryParams.idCardNumber"
                placeholder="请输入身份证号"
                maxlength="18"
                show-word-limit
                clearable
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="身份" prop="identityId" class="width_100">
              <el-select
                v-model="queryParams.identityId"
                placeholder="请选择身份"
                clearable
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.personnel_identity"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="年级" prop="gradeId">
              <el-select
                v-model="queryParams.gradeId"
                placeholder="请选择年级名称"
                style="width: 100%"
                @change="gradeFun_1"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="班级" prop="classId">
              <el-select
                v-model="queryParams.classId"
                placeholder="请选择班级"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in classList_1"
                  :key="index"
                  :value="item.id"
                  :label="item.className"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="是否启用" prop="isEnabled">
              <el-select
                v-model="queryParams.isEnabled"
                placeholder="请选择是否启用"
                style="width: 100%"
              >
                <el-option :value="1" label="启用"></el-option>
                <el-option :value="0" label="禁用"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="人脸状态" prop="faceStatus">
              <el-select
                v-model="queryParams.faceStatus"
                placeholder="请选择人脸状态"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in dict.type.facial_state"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="离校状态" prop="isGraduate">
              <el-select
                v-model="queryParams.isGraduate"
                placeholder="请选择离校状态"
                style="width: 100%"
              >
                <el-option label="在校" value="0"></el-option>
                <el-option label="离校" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item>
              <div class="dis aic">
                <div class="flex_1"></div>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="handleQuery"
                >
                  搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
                  重置
                </el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <!-- 按钮 -->
    <el-card class="search-card">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['student:person:add']"
            >新增</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['student:person:remove']"
            >删除</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['student:person:export']"
            >导出</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-edit"
            size="mini"
            @click="importStatus = true"
            v-hasPermi="['student:person:export']"
            >导入
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-edit"
            size="mini"
            @click="importFace = true"
            v-hasPermi="['student:person:export']"
            >导入人脸
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-edit"
            size="mini"
            @click="graduateStatusFun"
            v-hasPermi="['student:person:export']"
            >离校设置
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-card>
    <!-- 列表 -->
    <el-card class="table-card">
      <el-table
        v-loading="loading"
        :data="personList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="姓名" align="center" prop="name" width="100" />
        <el-table-column label="手机号" align="center" prop="phoneNumber" width="120" />
        <el-table-column
          label="身份证号"
          align="center"
          prop="idCardNumber"
          width="180"
        />
        <el-table-column label="学校" align="center" prop="schoolName" width="100" />
        <!-- v-hasPermi="['campus:classManage:school']" -->
        <el-table-column label="年级" align="center" prop="gradeName" width="120" />
        <!-- <el-table-column label=" 班级" align="center" prop="className" width="120" /> -->
        <el-table-column label="身份" align="center" prop="identityId">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.personnel_identity"
              :value="scope.row.identityId"
            />
          </template>
        </el-table-column>
        <el-table-column label="离校状态" align="center" prop="isGraduate">
          <template slot-scope="scope">
            <span v-if="scope.row.isGraduate == 1">离校</span>
            <span v-if="scope.row.isGraduate == 0">在校</span>
          </template>
        </el-table-column>
        <el-table-column label="钱包余额" align="center" prop="walletBalance" width="130">
          <template slot-scope="scope">
            {{ scope.row.walletBalance ? scope.row.walletBalance : 0 }}元
          </template>
        </el-table-column>
        <el-table-column
          label="单日消费限额"
          align="center"
          prop="dailySpendingLimit"
          width="100"
        >
          <template slot-scope="scope">
            {{ scope.row.dailySpendingLimit ? scope.row.dailySpendingLimit : 0 }}元
          </template>
        </el-table-column>
        <el-table-column
          label="单月消费限额"
          align="center"
          prop="monthlySpendingLimit"
          width="100"
        >
          <template slot-scope="scope">
            {{ scope.row.monthlySpendingLimit ? scope.row.monthlySpendingLimit : 0 }}元
          </template>
        </el-table-column>
        <el-table-column label="人脸状态" align="center" prop="faceStatus">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.facial_state" :value="scope.row.faceStatus" />
          </template>
        </el-table-column>
        <el-table-column
          label="人脸识别结果"
          align="center"
          prop="faceMessage"
          width="100"
        />
        <el-table-column label="是否启用" align="center" prop="isEnabled">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_open_status" :value="scope.row.isEnabled" />
          </template>
        </el-table-column>
        <el-table-column
          label="备注"
          align="center"
          prop="remarks"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="260"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              class="padding_4_10"
              @click="RechargeFun(scope.row)"
              v-hasPermi="['student:person:recharge']"
            >
              充值
            </el-button>
            <el-button
              type="primary"
              size="mini"
              class="padding_4_10"
              @click="addFaceFun(scope.row)"
              v-hasPermi="['student:person:editface']"
            >
              {{ scope.row.faceStatus ? "修改" : "添加" }}人脸
            </el-button>
            <el-button
              type="primary"
              size="mini"
              class="padding_4_10"
              v-if="scope.row.isGraduate == 0"
              @click="updatePersonGraduateFun(1, scope.row)"
            >
              离校
            </el-button>
            <!-- <el-button
              type="primary"
              size="mini"
              class="padding_4_10"
              v-if="scope.row.isGraduate == 1"
              @click="updatePersonGraduateFun(2, scope.row)"
            >
              在校
            </el-button> -->
            <el-button
              type="primary"
              size="mini"
              class="padding_4_10"
              @click="handleUpdate(scope.row)"
            >
              修改
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 添加或修改人员管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row>
          <el-col :span="20">
            <el-form-item label="姓名" prop="name" class="is-required">
              <el-input
                v-model="form.name"
                placeholder="请输入姓名"
                maxlength="50"
                show-word-limit
              />
            </el-form-item>
            <el-form-item label="手机号" prop="phoneNumber" class="is-required">
              <el-input
                v-model="form.phoneNumber"
                placeholder="请输入手机号"
                maxlength="11"
                show-word-limit
              />
            </el-form-item>
            <el-form-item label="身份证号" prop="idCardNumber" class="is-required">
              <el-input
                v-model="form.idCardNumber"
                placeholder="请输入身份证号"
                maxlength="18"
                show-word-limit
              />
            </el-form-item>
            <el-form-item label="年级" prop="gradeId" class="is-required">
              <el-select
                v-model="form.gradeId"
                placeholder="请选择年级"
                @change="gradeFun_2"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="班级" prop="classId" class="is-required">
              <el-select
                v-model="form.classId"
                placeholder="请选择班级"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in classList_2"
                  :key="index"
                  :value="item.id"
                  :label="item.className"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="身份" prop="identityId" class="is-required">
              <el-select
                v-model="form.identityId"
                placeholder="请选择身份"
                clearable
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.personnel_identity"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="是否启用" prop="isEnabled" class="is-required">
              <el-radio-group v-model="form.isEnabled">
                <el-radio :label="1">启用</el-radio>
                <el-radio :label="0">停用</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="备注" prop="remarks">
              <el-input
                type="textarea"
                v-model="form.remarks"
                placeholder="请输入备注"
                maxlength="200"
                :rows="3"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 充值 -->
    <el-dialog title="充值" :visible.sync="RechargeStatus" width="30%" append-to-body>
      <el-form ref="form" :model="RechargeForm" label-width="80px">
        <el-form-item label="金额" prop="name">
          <!--   -->
          <el-input
            v-model.number="RechargeForm.walletBalance"
            placeholder="请输入金额"
            maxlength="5"
          >
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="RechargeFormFun">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加、修改人脸 -->
    <el-dialog :title="faceTitle" :visible.sync="faceStatus" width="500px" append-to-body>
      <el-form ref="form" :model="faceForm" label-width="80px">
        <el-form-item label="照片" prop="fileName">
          <image-upload v-model="faceForm.fileName" limit="1" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="faceFormFun">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 人员导入 -->
    <el-dialog title="人员导入" :visible.sync="importStatus" width="500px" append-to-body>
      <div style="width: 100%">
        <el-button type="primary" @click="xzmb">下载模板</el-button>
        <div style="text-align: center; margin-top: 20px">
          <file-upload @success="fileSuccess" />
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="importStatus = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 人脸导入 -->
    <el-dialog title="人脸导入" :visible.sync="importFace" width="500px" append-to-body>
      <div style="width: 100%">
        <div style="text-align: center">
          <file-upload
            @success="fileSuccess"
            url="/campus/person/uploadFaceZip2OSS"
            :fileType="['zip']"
          />
          <!-- /campus/person/uploadFaceZip -->
        </div>
        <div>
          <el-divider content-position="left">说明</el-divider>
          <div>
            1.将图片文件以"年级_班级_姓名"命名，如:高三_一班_张三，一次最多可选1000张图片，不支持逐次累加。
          </div>
          <div>2.建议将单个图片压缩至300KB以下，以获得更高的处理效率,</div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="importFace = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 离校设置 -->
    <el-dialog
      title="离校设置"
      :visible.sync="goSchoolSetFormStatus"
      width="500px"
      append-to-body
    >
      <el-form :model="goSchoolSetForm" ref="queryForm" size="small" label-width="108px">
        <el-row>
          <el-form-item label="入学年份" prop="identityId" class="is-required">
            <el-date-picker
              v-model="goSchoolSetForm.admissionYear"
              type="year"
              placeholder="请选择入学年份"
              format="yyyy"
              value-format="yyyy"
              style="width: 100%"
              @change="queryPersonsByConditionFun"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="年级" prop="gradeId" class="is-required">
            <el-select
              v-model="goSchoolSetForm.gradeId"
              placeholder="请选择年级名称"
              style="width: 100%"
              clearable
              @change="queryPersonsByConditionFun_gradeFun"
            >
              <el-option
                v-for="(item, index) in gradeList"
                :key="index"
                :value="item.id"
                :label="item.gradeName"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="班级" prop="classId">
            <el-select
              v-model="goSchoolSetForm.classId"
              placeholder="请选择班级"
              clearable
              @change="queryPersonsByConditionFun"
              style="width: 100%"
            >
              <el-option
                v-for="(item, index) in queryPersonsByCondition_classList"
                :key="index"
                :value="item.id"
                :label="item.className"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="人员" prop="isGraduate">
            <el-select
              v-model="goSchoolSetForm.personId"
              placeholder="请选择人员"
              style="width: 100%"
              clearable
            >
              <el-option
                v-for="(item, index) in studentList"
                :key="index"
                :value="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="goSchoolSetFormFun">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  listPerson,
  getPerson,
  delPerson,
  addPerson,
  updatePerson,
  addRecharge,
  editFaceFun,
  personUpload,
  updatePersonGraduate,
  batchUpdatePersonGraduate,
  updatePersonGraduateByCondition,
  queryPersonsByCondition,
} from "@/api/campus/person";
import { listGrade } from "@/api/campus/grade";
import { listClassManage } from "@/api/campus/classManage";

export default {
  name: "studentPerson",
  dicts: ["facial_state", "sys_open_status", "personnel_identity"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员管理表格数据
      personList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        idCardNumber: null,
        schoolName: null,
        gradeName: null,
        className: null,
        identityName: null,
        identityId: null,
        walletBalance: null,
        dailySpendingLimit: null,
        monthlySpendingLimit: null,
        faceStatus: null,
        phoneNumber: null,
        isEnabled: null,
      },
      goSchoolSetForm: {
        gradeId: "", //年级ID
        classId: "", //班级ID
        admissionYear: "", //入学年份
        personId: "",
      },
      queryPersonsByCondition_classList: [],
      goSchoolSetFormStatus: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
        idCardNumber: [{ required: true, message: "身份证号不能为空", trigger: "blur" }],
      },
      gradeList: [],
      classList_1: [],
      classList_2: [],

      RechargeStatus: false,
      RechargeForm: {
        id: "",
        walletBalance: "",
      },
      faceTitle: "",
      faceStatus: false,
      faceForm: {
        id: "",
        fileName: "",
      },
      importStatus: false,
      importFace: false,
      studentList: [],
    };
  },
  created() {
    this.getList();
    this.listGradeFun();
    this.gradeFun_1();
    this.gradeFun_2();
  },
  activated() {
    this.getList();
    this.listGradeFun();
    this.gradeFun_1();
    this.gradeFun_2();
  },
  methods: {
    /** 查询人员管理列表 */
    getList() {
      this.loading = true;
      listPerson(this.queryParams).then((response) => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    listGradeFun() {
      listGrade({ pageNum: 1, pageSize: 200 }).then((res) => {
        if (res.code == 200) {
          this.gradeList = res.rows;
        }
      });
    },
    gradeFun_1(options) {
      this.$set(this.queryParams, "classId", "");
      listClassManage({ pageNum: 1, pageSize: 200, gradeId: options }).then(
        (response) => {
          this.classList_1 = response.rows;
        }
      );
    },
    gradeFun_2(options) {
      listClassManage({ pageNum: 1, pageSize: 200, gradeId: options }).then(
        (response) => {
          this.classList_2 = response.rows;
        }
      );
    },
    queryPersonsByConditionFun_gradeFun(options) {
      this.$set(this.goSchoolSetForm, "classId", "");
      var that = this;
      listClassManage({ pageNum: 1, pageSize: 200, gradeId: options }).then(
        (response) => {
          this.queryPersonsByCondition_classList = response.rows;
          that.queryPersonsByConditionFun();
        }
      );
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.RechargeStatus = false;
      this.faceStatus = false;
      this.goSchoolSetFormStatus = false;
      this.goSchoolSetForm = {};
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        idCardNumber: null,
        schoolName: null,
        schoolId: null,
        gradeName: null,
        gradeId: null,
        className: null,
        classId: null,
        identityName: null,
        identityId: null,
        walletBalance: null,
        dailySpendingLimit: null,
        monthlySpendingLimit: null,
        faceStatus: 0,
        forceVerification: null,
        tagNumber: null,
        phoneNumber: null,
        remarks: null,
        isEnabled: 1,
        createdAt: null,
        createdBy: null,
        walletBalanceList: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryParams");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.walletBalanceList = selection.map((item) => item.walletBalance);

      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.isEnabled = 1;
      this.open = true;
      this.title = "添加人员管理";
      this.gradeFun_2();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPerson(id).then((response) => {
        this.form = response.data;
        this.form.identityId = this.form.identityId + "";
        // this.form.faceStatus = this.form.faceStatus.split(",");
        this.open = true;
        this.title = "修改人员管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      var that = this;
      var data = {...this.form};
      if (!data.name) {
        return that.$modal.msgError("请输入姓名");
      }
      if (!data.phoneNumber) {
        return that.$modal.msgError("请输入手机号");
      }
      if (!data.idCardNumber) {
        return that.$modal.msgError("请输入身份证号");
      }
      if (!data.gradeId) {
        return that.$modal.msgError("请选择年级");
      }
      if (!data.classId) {
        return that.$modal.msgError("请选择班级");
      }
      if (!data.identityId) {
        return that.$modal.msgError("请选择身份");
      }
      data.isEnabled = data.isEnabled + "";
      if (!data.isEnabled) {
        return that.$modal.msgError("请选择是否启用");
      }
      if (data.idCardNumber.indexOf("*") > 0) {
        return this.$modal.msgError("请输入正确的身份证号");
      }
      if (data.id != null) {
        updatePerson(data).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
        });
      } else {
        addPerson(data).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      }
    },
    // 充值
    RechargeFun(row) {
      this.RechargeStatus = true;
      this.RechargeForm.id = row.id;
    },
    RechargeFormFun() {
      var data = this.RechargeForm;
      if (!data.id) {
        return this.$modal.msgError("人员错误");
      }
      if (!data.walletBalance) {
        return this.$modal.msgError("请输入正确的金额");
      }
      var reg = /^\d+$/;
      if (!reg.test(data.walletBalance)) {
        return this.$modal.msgError("请输入正确的金额");
      }
      data.walletBalance = Math.abs(data.walletBalance);
      addRecharge(data).then((response) => {
        this.$modal.msgSuccess("操作成功");
        this.RechargeStatus = false;
        this.RechargeForm = {};
        this.getList();
      });
    },
    addFaceFun(row) {
      this.faceStatus = true;
      this.faceForm.id = row.id;
      this.faceForm.fileName = row.fileName;
      console.log(this.faceForm.id, " this.faceForm.id  this.faceForm.id ");
      if (row.faceStatus) {
        this.faceTitle = "修改人脸";
      } else {
        this.faceTitle = "添加人脸";
      }
    },
    faceFormFun() {
      var data = this.faceForm;
      if (!data.id) {
        return this.$modal.msgError("人员错误");
      }
      if (!data.fileName) {
        return this.$modal.msgError("请上传照片");
      }
      editFaceFun(data).then((response) => {
        this.$modal.msgSuccess("操作成功");
        this.faceStatus = false;
        this.getList();
        this.faceForm = {};
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      var status = false;
      this.walletBalanceList.map((item) => {
        if (item != 0) {
          status = true;
        }
      });
      if (status) {
        return this.$modal.msgError("被删除人员中存在余额无法删除");
      }
      this.$modal
        .confirm("是否确认删除该人员？")
        .then(function () {
          return delPerson(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "campus/person/export",
        {
          ...this.queryParams,
        },
        "人员" + `_${new Date().getTime()}.xlsx`
      );
    },
    uploadFile(options) {
      console.log(options);
      if (options.file.size < 1) {
        return this.$modal.msgError("文件大小错误");
      }
      let formData = new FormData();
      formData.append("file", options.file);
      var that = this;
      personUpload(formData)
        .then((response) => {
          if (response.code == 200) {
            that.$modal.msgSuccess("上传成功");
          } else {
            that.$modal.msgError(response.msg);
          }
        })
        .catch((error) => {
          console.error(error);
        });
    },
    xzmb() {
      window.open(
        "https://school.leyibei.com/api/common/downloads?filename=人员导入表.xls",
        "_blank"
      );
    },
    // 上传后返回
    fileSuccess() {
      this.importFace = false;
      this.faceStatus = false;
      this.importStatus = false;
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getList();
    },
    // 状态
    graduateStatusFun() {
      this.goSchoolSetFormStatus = true;
    },
    // 操作
    goSchoolSetFormFun() {
      var data = this.goSchoolSetForm;
      var that = this;
      if (!data.admissionYear) {
        return that.$modal.msgError("请选择入学年份");
      }
      if (!data.gradeId) {
        return that.$modal.msgError("请选择年级");
      }
      updatePersonGraduateByCondition(data).then((response) => {
        if (response.code == 200) {
          that.getList();
          that.goSchoolSetFormStatus = false;
          that.$modal.msgSuccess("设置成功");
        } else {
          that.$modal.msgError(response.msg);
        }
      });
    },
    graduateFun() {
      var data = this.queryParams;
      if (!data.gradeId) {
        return this.$modal.msgError("设置离校人员需要设置年级名称");
      }
      this.$confirm("此操作将批量人员设置为离校,是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((res) => {
          console.log(res, "rrrrrrr");

          batchUpdatePersonGraduate(data)
            .then((response) => {
              if (response.code == 200) {
                that.getList();
                that.$modal.msgSuccess("设置成功");
              } else {
                that.$modal.msgError(response.msg);
              }
            })
            .catch((error) => {
              console.error(error);
            });
        })
        .catch(() => {});
    },
    queryPersonsByConditionFun() {
      var data = this.goSchoolSetForm;
      data.isGraduate = 0;
      if (!data.classId) {
        return;
      }
      var that = this;
      queryPersonsByCondition(data).then((res) => {
        if (res.code == 200) {
          that.studentList = res.data;
        }
      });
    },

    updatePersonGraduateFun(options, value) {
      var that = this;
      var str = "";
      if (options == 1) {
        str = "此操作将人员设置为离校,是否继续?";
      } else if (options == 2) {
        str = "此操作将人员设置为在校,是否继续?";
      }
      this.$confirm(str, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((res) => {
          var data = {};
          if (options == 1) {
            data = {
              personId: value.id,
              isGraduate: 1,
            };
          } else if (options == 2) {
            data = {
              personId: value.id,
              isGraduate: 0,
            };
          }
          updatePersonGraduate(data)
            .then((response) => {
              if (response.code == 200) {
                that.getList();
                that.$modal.msgSuccess("设置成功");
              } else {
                that.$modal.msgError(response.msg);
              }
            })
            .catch((error) => {
              console.error(error);
            });
        })
        .catch(() => {});
    },
  },
};
</script>
<style>
.formBox >>> .el-form-item--small.el-form-item {
  margin-bottom: 0px !important;
}

.formBox >>> .el-form-item__label {
  font-size: 12px !important;
  padding: 0 !important;
}
</style>
